import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author yu
 * @date 2025/6/4 19:00
 * @description: 17. 电话号码的字母组合
 * 给定一个仅包含数字 2-9 的字符串，返回所有它能表示的字母组合。答案可以按 任意顺序 返回。
 * 给出数字到字母的映射如下（与电话按键相同）。注意 1 不对应任何字母。
 * 示例 1：
 * 输入：digits = "23"
 * 输出：["ad","ae","af","bd","be","bf","cd","ce","cf"]
 */
public class backtracking_17 {
    public static String[] letterMap = {
            "",    //0
            "",     //1
            "abc",  //2
            "def",  //3
            "ghi",  //4
            "jkl",  //5
            "mno",  //6
            "pqrs", //7
            "tuv",  //8
            "wxyz"  //9
    };
    public static List<String> result = new ArrayList<>();
    public static StringBuilder temp = new StringBuilder();

    public static List<String> letterCombinations(String digits) {
        if (digits == null || digits.isEmpty()) {
            return result; // 处理空输入
        }
        backTracking(digits, 0);
        return result;
    }

    public static void backTracking(String digits, int index) {
        if (index == digits.length()) {
            result.add(temp.toString());
            return;
        }
        int digit = digits.charAt(index) - '0';
        String letters = letterMap[digit];
        for (int i = 0; i < letters.length(); i++) {
            temp.append(letters.charAt(i));
            backTracking(digits, index + 1);
            temp.deleteCharAt(temp.length() - 1);
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String digits = scanner.nextLine().trim();
        List<String> res = letterCombinations(digits);
        System.out.println(res);
    }
}
